<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户标示id" prop="disUserId">
        <el-input
          v-model="queryParams.disUserId"
          placeholder="请输入用户标示id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户名称" prop="disUserName">
        <el-input
          v-model="queryParams.disUserName"
          placeholder="请输入用户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="类型" prop="identityType">
        <el-select v-model="queryParams.identityType" placeholder="请选择类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="添加时间" prop="addTime">
        <el-input
          v-model="queryParams.addTime"
          placeholder="请输入添加时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="amountStatus">
        <el-select v-model="queryParams.amountStatus" placeholder="请选择状态" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['distribution:amount:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="amountList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="邀请用户可用积分" align="center" prop="id" />
      <el-table-column label="用户标示id" align="center" prop="disUserId" />
      <el-table-column label="用户名称" align="center" prop="disUserName" />
      <el-table-column label="总金额" align="center" prop="totalAmount" />
      <el-table-column label="冻结金额" align="center" prop="frozenAmount" />
      <el-table-column label="可用金额" align="center" prop="avaibleAmount" />
      <el-table-column label="类型" align="center" prop="identityType" />
      <el-table-column label="添加时间" align="center" prop="addTime" />
      <el-table-column label="状态" align="center" prop="amountStatus" />
      <el-table-column label="交易账户总金额" align="center" prop="tradeTotalAmount" />
      <el-table-column label="交易账户冻结金额" align="center" prop="tradeFrozenAmount" />
      <el-table-column label="交易账户可用金额" align="center" prop="tradeAvaibleAmount" />
      <el-table-column label="等级账户总金额" align="center" prop="levelTotalAmount" />
      <el-table-column label="等级账户冻结金额" align="center" prop="levelFrozenAmount" />
      <el-table-column label="等级账户可用金额" align="center" prop="levelAvaibleAmount" />
      <el-table-column label="邀请用户总积分" align="center" prop="inviteTotalAmount" />
      <el-table-column label="邀请用户冻结积分" align="center" prop="inviteFrozenAmount" />
      <el-table-column label="邀请用户可用积分" align="center" prop="inviteAvaibleAmount" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改账户金额对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户标示id" prop="disUserId">
          <el-input v-model="form.disUserId" placeholder="请输入用户标示id" />
        </el-form-item>
        <el-form-item label="用户名称" prop="disUserName">
          <el-input v-model="form.disUserName" placeholder="请输入用户名称" />
        </el-form-item>
        <el-form-item label="总金额" prop="totalAmount">
          <el-input v-model="form.totalAmount" placeholder="请输入总金额" />
        </el-form-item>
        <el-form-item label="冻结金额" prop="frozenAmount">
          <el-input v-model="form.frozenAmount" placeholder="请输入冻结金额" />
        </el-form-item>
        <el-form-item label="可用金额" prop="avaibleAmount">
          <el-input v-model="form.avaibleAmount" placeholder="请输入可用金额" />
        </el-form-item>
        <el-form-item label="类型" prop="identityType">
          <el-select v-model="form.identityType" placeholder="请选择类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="添加时间" prop="addTime">
          <el-input v-model="form.addTime" placeholder="请输入添加时间" />
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.amountStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="交易账户总金额" prop="tradeTotalAmount">
          <el-input v-model="form.tradeTotalAmount" placeholder="请输入交易账户总金额" />
        </el-form-item>
        <el-form-item label="交易账户冻结金额" prop="tradeFrozenAmount">
          <el-input v-model="form.tradeFrozenAmount" placeholder="请输入交易账户冻结金额" />
        </el-form-item>
        <el-form-item label="交易账户可用金额" prop="tradeAvaibleAmount">
          <el-input v-model="form.tradeAvaibleAmount" placeholder="请输入交易账户可用金额" />
        </el-form-item>
        <el-form-item label="等级账户总金额" prop="levelTotalAmount">
          <el-input v-model="form.levelTotalAmount" placeholder="请输入等级账户总金额" />
        </el-form-item>
        <el-form-item label="等级账户冻结金额" prop="levelFrozenAmount">
          <el-input v-model="form.levelFrozenAmount" placeholder="请输入等级账户冻结金额" />
        </el-form-item>
        <el-form-item label="等级账户可用金额" prop="levelAvaibleAmount">
          <el-input v-model="form.levelAvaibleAmount" placeholder="请输入等级账户可用金额" />
        </el-form-item>
        <el-form-item label="邀请用户总积分" prop="inviteTotalAmount">
          <el-input v-model="form.inviteTotalAmount" placeholder="请输入邀请用户总积分" />
        </el-form-item>
        <el-form-item label="邀请用户冻结积分" prop="inviteFrozenAmount">
          <el-input v-model="form.inviteFrozenAmount" placeholder="请输入邀请用户冻结积分" />
        </el-form-item>
        <el-form-item label="邀请用户可用积分" prop="inviteAvaibleAmount">
          <el-input v-model="form.inviteAvaibleAmount" placeholder="请输入邀请用户可用积分" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAmount, getAmount, delAmount, addAmount, updateAmount, exportAmount } from "@/api/distribution/amount";

export default {
  name: "Amount",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 账户金额表格数据
      amountList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        disUserId: null,
        disUserName: null,
        totalAmount: null,
        frozenAmount: null,
        avaibleAmount: null,
        identityType: null,
        addTime: null,
        amountStatus: null,
        tradeTotalAmount: null,
        tradeFrozenAmount: null,
        tradeAvaibleAmount: null,
        levelTotalAmount: null,
        levelFrozenAmount: null,
        levelAvaibleAmount: null,
        inviteTotalAmount: null,
        inviteFrozenAmount: null,
        inviteAvaibleAmount: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询账户金额列表 */
    getList() {
      this.loading = true;
      listAmount(this.queryParams).then(response => {
        this.amountList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        disUserId: null,
        disUserName: null,
        totalAmount: null,
        frozenAmount: null,
        avaibleAmount: null,
        identityType: null,
        addTime: null,
        updateTime: null,
        amountStatus: "0",
        tradeTotalAmount: null,
        tradeFrozenAmount: null,
        tradeAvaibleAmount: null,
        levelTotalAmount: null,
        levelFrozenAmount: null,
        levelAvaibleAmount: null,
        inviteTotalAmount: null,
        inviteFrozenAmount: null,
        inviteAvaibleAmount: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加账户金额";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAmount(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改账户金额";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAmount(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAmount(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除账户金额编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delAmount(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有账户金额数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportAmount(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
